var app = getApp();
import config from '@/config/config'

Component({
  data: {
    current: 0,
    index: 0,
    color: "#C4CBD9",
    selectedColor: "#0C4DF9", // 被选中颜色
    list: []
  },
  lifetimes: {
    attached() {
      console.log('dsfds');
      let roleId = wx.getStorageSync('roleId')
      if (roleId) {
        const list = [
          {
            pagePath: '/pages/unitCheck/unitCheck',
            iconPath: '../assets/image/unitCheck2.png',
            selectedIconPath: '../assets/image/unitCheck.png',
            text: '单位自查'
          },
          {
            pagePath: '/pages/orderList/orderList',
            iconPath: '../assets/image/orderList2.png',
            selectedIconPath: '../assets/image/orderList.png',
            text: '工单列表'
          },
          {
            pagePath: '/pages/dataStatis/dataStatis',
            iconPath: '../assets/image/dataStatis2.png',
            selectedIconPath: '../assets/image/dataStatis.png',
            text: '数据统计'
          },
          {
            pagePath: '/pages/personInfo/personInfo',
            iconPath: '../assets/image/my2.png',
            selectedIconPath: '../assets/image/my.png',
            text: '个人信息'
          }
        ]
  
        const list2 = [
          {
            pagePath: '/pages/unitCheck/unitCheck',
            iconPath: '../assets/image/gridIcon2.png',
            selectedIconPath: '../assets/image/gridIcon.png',
            text: '网格巡查'
          },
          {
            pagePath: '/pages/orderList/orderList',
            iconPath: '../assets/image/orderList2.png',
            selectedIconPath: '../assets/image/orderList.png',
            text: '工单列表'
          },
          {
            pagePath: '/pages/dataStatis/dataStatis',
            iconPath: '../assets/image/dataStatis2.png',
            selectedIconPath: '../assets/image/dataStatis.png',
            text: '数据统计'
          },
          {
            pagePath: '/pages/personInfo/personInfo',
            iconPath: '../assets/image/my2.png',
            selectedIconPath: '../assets/image/my.png',
            text: '个人信息'
          }
        ]
  
        const list3 = [
          {
            pagePath: '/pages/unitCheck/unitCheck',
            iconPath: '../assets/image/fireFighting2.png',
            selectedIconPath: '../assets/image/fireFighting.png',
            text: '消防督察'
          },
          {
            pagePath: '/pages/orderList/orderList',
            iconPath: '../assets/image/orderList2.png',
            selectedIconPath: '../assets/image/orderList.png',
            text: '工单列表'
          },
          {
            pagePath: '/pages/cockpit/cockpit',
            iconPath: '../assets/image/cockpit2.png',
            selectedIconPath: '../assets/image/cockpit.png',
            text: '驾驶舱'
          },
          {
            pagePath: '/pages/personInfo/personInfo',
            iconPath: '../assets/image/my2.png',
            selectedIconPath: '../assets/image/my.png',
            text: '个人信息'
          }
        ]
        let preFix = roleId.split("-")[0]
        if (preFix == 'unit') { // 单位
          this.setData({ list: list })
        } else if (preFix == 'gridding') { // 网格
          this.setData({ list: list2 })
        } else if (preFix == 'fireFighting') { // 消防
          this.setData({ list: list3 })
        }
      }
      
    },

  },

  methods: {
    switchTab(e) {
      console.log(e);
      let url = e.currentTarget.dataset.path
      let index = e.currentTarget.dataset.index
      this.getTabBar().setData({ current: index })
      if (url) {
        wx.switchTab({ url })
      }
    }
  },
});
